#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=700;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL check(LL x1,LL y1,LL x2,LL y2,LL r1,LL r2){

    if(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2)<=(r1+r2)*(r1+r2)){
        return 1;
    }
    else return 0;
}
struct Point{
  LL x,y,r;
}p[maxn];
Point roun[maxn];
LL cnt=0;
int main(void)
{
 /// cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,k,R;n=read();k=read();R=read();
 /// LL num=0;
  for(LL i=-12;i<=12;i++){
    for(LL j=-12;j<=12;j++){
        roun[++cnt].r=R;
        roun[cnt].x=i;
        roun[cnt].y=j;
    ///    num++;
     ///   debug(num);
    }
  }
  ///debug(cnt);
  for(LL i=1;i<=n;i++){
    //cin>>p[i].x>>p[i].y>>p[i].r;
    p[i].x=read();p[i].y=read();p[i].r=read();
  }
  LL ans=0;
  if(k==1){

     ///   debug(cnt);
        for(LL i=1;i<=cnt;i++){
            LL sum=0;
            for(LL j=1;j<=n;j++){
                if(check(roun[i].x,roun[i].y,p[j].x,p[j].y,roun[i].r,p[j].r)){
                    sum++;
                    continue;
                }
            }
             ans=max(ans,sum);
        }

  }
  else if(k==2){

        for(LL i=1;i<=cnt;i++){
            for(LL j=i+1;j<=cnt;j++){
                LL sum=0;
                for(LL k=1;k<=n;k++){
                    if(check(roun[i].x,roun[i].y,p[k].x,p[k].y,roun[i].r,p[k].r)||check(roun[j].x,roun[j].y,p[k].x,p[k].y,roun[i].r,p[k].r)){
                        sum++;
                        continue;
                    }
                }
                ans=max(ans,sum);
            }
        }
  }
  else if(k==3){

        for(LL i=1;i<=cnt;i++){
            for(LL j=i+1;j<=cnt;j++){
                for(LL k=j+1;k<=cnt;k++){
                    LL sum=0;
                    for(LL z=1;z<=n;z++){
                        if(check(roun[i].x,roun[i].y,p[z].x,p[z].y,roun[i].r,p[z].r)||check(roun[j].x,roun[j].y,p[z].x,p[z].y,roun[i].r,p[z].r)||check(roun[k].x,roun[k].y,p[z].x,p[z].y,roun[k].r,p[z].r)){
                            sum++;
                            continue;
                        }
                    }
                    ans=max(ans,sum);
                }
            }
        }

  }
  printf("%d\n",ans);

return 0;
}
